使用Google GCP搭建专属免费VPS

郑重申明:本文用于记录、总结、分享云服务器自行搭建VPS的过程及方法。如将其作用于违反法律法规的事情,与本人无关。请遵守当地法律法规。

简介

感谢谷歌提供的GCP服务(Google Cloud Platform,谷歌云平台服务),首次注册激活GCP,你会获享12个月试用期和$300 赠金,是不是免费?

请注意:教程很详细,图很多!

image.png

首先你需要

  • 谷歌账号以及能访问谷歌站点的一台电脑(首先你要能登录谷歌GCP)
  • 外币卡(VISA、Mastercard、AE)(实测招行VISA全币种卡可以)

开始搭建

1. 登录 Google Cloud Platform 激活账户填写相关信息

  • 右上角点击language修改语言为中文简体(如果你的英文很棒那么可以不用改)
  • 点击右上角免费试用
  • 国家/地区可以选择香港,点击继续,登录谷歌账户

image.png

  • 填写个人信息和信用卡信息

    账户类型记得选个人

    信用卡必须填写。填写之后点击开始免费使用。

    谷歌声称“我们要求您提供信用卡信息是为了确认您不是机器人。除非您手动升级为付费帐号,否则我们不会向您收费。”具体信息可以参考:https://www.youtube.com/watch?v=kJHKsOywfxE

image.png

  • 激活成功之后你会看到如下界面,并且会有提示$300美金和12个月免费试用期。

image.png

2. 创建VM虚拟机实例

  • 左侧导航栏选择 计算 —> Computer Engine —> VM实例

image.png

  • 等待 Compute Engine 启用完成后,点击创建,开始自定义实例配置

image.png

- 填写 名称
- 选择 区域 及 地区(日本站点距离近,响应速度快)
- 调整一下 内核 及 内存,选择最低共享配置即可满足
- 更改 启动磁盘 为 Ubuntu 18.04 LTS

image.png

- 防火墙勾选 允许 HTTP 流量 允许 HTTPS 流量
- 点击 创建,创建完成如下图。

image.png

3. 设置防火墙规则

  • 左侧菜单栏 —> 网络 —> VPC网络 —> 防火墙规则

image.png

  • 点击创建防火墙规则

image.png

- 名称 按规则自定义
- 目标 选择  网络中的所有实例

image.png

- 来源ip地址范围 0.0.0.0/0
- 协议和端口 勾选 UDP 填写 500,4500,勾选 其他协议 填写 esp
- 点击 创建,创建成功,如下图

image.png

4. 配置VPC网络

image.png

- 左侧菜单栏 ---> 网络 ---> VPC网络 ---> default

image.png

- 点击修改

image.png

- 子网创建模式 选择 自动
- 动态路由模式 选择 全局
- 点击保存即可

5. 设置 负载平衡

image.png

  • 左侧菜单栏 —> 网络 —> 负载平衡
  • 点击创建负载平衡
  • 直接点击继续

image.png

- 名称 按规则自定义填写
- 选择 区域
- 选择第一步所创建的VM实例
- 点击前端配置

image.png

- 名称 按规则自定义填写
- 端口 填写500-4500
- 点击 完成 
- 点击 创建,创建完成如下

image.png

6. 登录服务器

  • 导航菜单 → Compute Engine → VM实例

image.png

  • 点击 SSH,会进入到远程终端页面

image.png

7. 开始部署服务

  • 执行以下命令
    1
    sudo apt-get update && apt-get dist-upgrade
控制台输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
zuoqianheng@instance-1:~$ sudo apt-get update && apt-get dist-upgrade
Hit:1 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [8570 kB]
Get:5 http://archive.canonical.com/ubuntu bionic InRelease [10.2 kB]
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:7 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/universe Translation-en [4941 kB]
Get:8 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [151 kB]
Get:9 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/multiverse Translation-en [108 kB]
Get:10 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [682 kB]
Get:11 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [251 kB]
Get:12 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [970 kB]
Get:13 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [293 kB]
Get:14 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [6640 B]
Get:15 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [3556 B]
Get:16 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [2512 B]
Get:17 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/main Translation-en [1644 B]
Get:18 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [3736 B]
Get:19 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1696 B]
Get:20 http://archive.canonical.com/ubuntu bionic/partner amd64 Packages [2320 B]
Get:21 http://archive.canonical.com/ubuntu bionic/partner Translation-en [1276 B]
Get:22 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [450 kB]
Get:23 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [156 kB]
Get:24 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [570 kB]
Get:25 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [185 kB]
Get:26 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [4008 B]
Get:27 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [2060 B]
Fetched 17.6 MB in 4s (4193 kB/s)
Reading package lists... Done
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
zuoqianheng@instance-1:~$
  • 命令行一步部署VPN服务
1
2
3
4
wget https://git.io/vpnsetup -O vpnsetup.sh && sudo \
VPN_IPSEC_PSK='预分享密钥' \
VPN_USER='用户名' \
VPN_PASSWORD='密码' sh vpnsetup.sh
记得修改命令中的个人信息部分。
一个安全的 IPsec PSK 应该至少包含 20 个随机字符。
需要等待大概5-10分钟后,控制台输出

image.png

详细部署VPN服务教程可参考:IPsec VPN 服务器一键安装脚本

  • 看到上图,我们的的VPN就算搭建成功了
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ================================================
    IPsec VPN server is now ready for use!
    Connect to your new VPN with these details:
    Server IP: 34.*******
    IPsec PSK: ********************
    Username: ******************
    Password: ***************
    Write these down. You'll need them to connect!
    Important notes: https://git.io/vpnnotes
    Setup VPN clients: https://git.io/vpnclients
    ================================================
    zuoqianheng@instance-1:~$

8. 如何连接?

  • Mac、iOS设置可以直接在网络设置中找到VPN,添加对应的服务器、用户名、密码等数据即可访问。Windows 用户可以使用免费的 Shrew Soft 客户端。可以参考这里:配置 IPsec/XAuth VPN 客户端
  • 如果无法连接,请首先检查是否输入了正确的 VPN 登录凭证。

Info

参考链接


-------------本文结束感谢您的阅读-------------